from django.db import models
from common.snowflake import Snowflake


class Account(models.Model):
    """
    账户相关模型
    """
    id = models.BigIntegerField(primary_key=True, default=Snowflake.generate, verbose_name="主键")
    name = models.CharField(max_length=50, blank=True, null=True, verbose_name="名称")
    mobile = models.CharField(max_length=50, blank=True, null=True, verbose_name="手机号")
    avatar = models.CharField(max_length=255, blank=True, null=True, verbose_name="头像")
    password = models.CharField(max_length=128, blank=True, null=True, verbose_name="密码")
    salt = models.CharField(max_length=64, blank=True, null=True, verbose_name="加密盐")
    # TODO 账号注册的时候不需要省市区
    province = models.CharField(max_length=64, blank=True, null=True, verbose_name="省")
    province_code = models.CharField(max_length=50, blank=True, null=True, verbose_name="省码")
    city = models.CharField(max_length=64, blank=True, null=True, verbose_name="市")
    city_code = models.CharField(max_length=50, blank=True, null=True, verbose_name="市码")
    district = models.CharField(max_length=128, blank=True, null=True, verbose_name="区")
    district_code = models.CharField(max_length=50, blank=True, null=True, verbose_name="区码")
    address = models.CharField(max_length=255, blank=True, null=True, verbose_name="地址")
    # TODO 注册账号默认经销商是 reseller_id = 1 reseller_name = 芯海智控
    reseller_id = models.BigIntegerField(blank=True, null=True, verbose_name="分销商id")
    reseller_name = models.CharField(max_length=50, blank=True, null=True, verbose_name="分销商名称")
    # 第三方用户的ID主要是用来进行同步，例如SaaS收银软件向我们创建账户
    # 默认的app_user_id为空
    app_user_id = models.CharField(max_length=128, blank=True, null=True, verbose_name="三方ID")

    class Meta:
        # TODO 修改表名称
        db_table = 'fe_customer'
        managed = False


class Reseller(models.Model):
    """
    经销商相关模型

    在license项目中，经销商只是用来呈现，可能不需要这么多字段的呈现；
    """
    id = models.BigIntegerField(primary_key=True, default=Snowflake.generate, verbose_name="主键")
    name = models.CharField(max_length=50, blank=True, null=True, verbose_name="名称")
    tel = models.CharField(max_length=50, blank=True, null=True, verbose_name="电话")
    mobile = models.CharField(max_length=50, blank=True, null=True, verbose_name="手机号")
    password = models.CharField(max_length=128, blank=True, null=True, verbose_name="密码")
    salt = models.CharField(max_length=64, blank=True, null=True, verbose_name="加密盐")
    type = models.IntegerField(blank=True, null=True, verbose_name="类型")
    level = models.IntegerField(blank=True, null=True, verbose_name="等级")
    contact = models.CharField(max_length=32, blank=True, null=True, verbose_name="联系人")
    website = models.CharField(max_length=255, blank=True, null=True, verbose_name="网址")
    # TODO 这个字段的更新需要定时任务吧
    customer_count = models.IntegerField(blank=True, null=True, verbose_name="客户数量")
    remark = models.CharField(max_length=255, blank=True, null=True, verbose_name="针对经销商备注")
    province = models.CharField(max_length=64, blank=True, null=True, verbose_name="省")
    province_code = models.CharField(max_length=50, blank=True, null=True, verbose_name="省码")
    city = models.CharField(max_length=64, blank=True, null=True, verbose_name="市")
    city_code = models.CharField(max_length=50, blank=True, null=True, verbose_name="市码")
    district = models.CharField(max_length=64, blank=True, null=True, verbose_name="区")
    district_code = models.CharField(max_length=50, blank=True, null=True, verbose_name="区码")
    address = models.CharField(max_length=255, blank=True, null=True, verbose_name="地址")
    session_key = models.CharField(max_length=100, blank=True, null=True, verbose_name="session_key")
    open_id = models.CharField(max_length=64, blank=True, null=True, verbose_name="小程序唯一标识")
    mp_open_id = models.CharField(max_length=64, blank=True, null=True, verbose_name="公众号唯一标识")
    union_id = models.CharField(max_length=64, blank=True, null=True, verbose_name="微信公众平台唯一标识")
    avatar = models.CharField(max_length=255, blank=True, null=True, verbose_name="头像")
    balance = models.IntegerField(blank=True, null=True, verbose_name="账户余额")
    status = models.IntegerField(blank=True, null=True, verbose_name="状态 1正常/0禁用")

    class Meta:
        db_table = 'fe_reseller'
        managed = False